import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router';
const loadModuleRoute = (
  path: string,
  component: Promise<any>,
  record: Record<string, { [key: string]: any }>
) => {
  const children: RouteRecordRaw[] = [];
  Object.values(Object.values(record)[0]).forEach(item => {
    children.push(...item);
  });
  return {
    path,
    component,
    children,
  } as RouteRecordRaw;
};
export default createRouter({
  history: createWebHistory(),
  routes: [
    {
      path: '/',
      redirect: '/home',
    },
    {
      path: '/home',
      component: () => import('@/components/home.vue'),
      children: [
        {
          name: 'children-one',
          path: 'children-one/:name/:age',
          component: () => import('@/components/home-children-one.vue'),
          props: true,
        },
        {
          path: 'children-two',
          name: 'children-two',
          component: () => import('@/components/home-children-two.vue'),
          props: true,
        },
      ],
    },
    loadModuleRoute(
      '/about',
      import('@/components/about/index.vue'),
      import.meta.globEager('./modules/about.ts')
    ),
  ],
});
